home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
CC_C
/
H156.ZIP
/
README.TXT
< prev
next >
Wrap
Text File
|
1992-07-16
|
84KB
|
2,407 lines
GNE C/C++ UTILITIES
Version 1.0
Copyright (c) 1992 G.N.E. SOFTWARE LTD.
This is a shareware copy of the utilities, which you may use to evaluate its
suitability for your needs. If you decide that the utilities are of use
to you, then you must register to continue using them.
In order to encourage registration the shareware copy of the utilities
are resticted to processing source files of up to 500 lines long. They will
not correctly process source files longer than this.
Registration provides the following benefits:
o Latest version of the utilities with support for unlimited length
source files.
o Printed version of the full manual.
o Technical support.
See the file REGISTER.TXT for details on how to register.
G.N.E. SOFTWARE LTD. accept no responsiblity or liability for any loss or
damage arising from the use or misuse of this software.
All Company names and product names are registered trademarks or trademarks
of their respective companies.
GNE C/C++ UTILITIES
1 Introduction
GNE C/C++ UTILITIES is a collection of 7 tools aimed at making
C/C++ software development more efficient.
The following utilities are provided:
CB Reformats source code to your chosen layout
style, thereby making it easier for you to read.
CCALLS Shows the function call tree. Also shows non-
called functions and possible candidates for
making static.
CDEF Performs a partial pre-processor pass to remove
old or redundant code within #if, #ifdef and
#ifndef statements for specified defines, making
the code easier to read.
CDOC Allows documentation to be produced by extracting
specially marked comment blocks from the source
code, making it easier to produce the
documentation in the first place and to maintain
it.
CPROTO Generates function prototypes as required by ANSI
compliant compilers. The prototypes include the
same data types as used by the function as
opposed to the base types that they may be
defined from.
CPR Source printer which has knowledge about the
C/C++ language which allows it to highlight
function names, produce index of function names
and start each function on a new page all of
which help to make it easier to find your way
through large source listings. Double sided
printing is supported and it is also possible to
print multiple pages on each side of the paper.
FINDDIV Finds all occurrences of possible / and %
operations. Suitable for making sure that divide
by zero errors can't occur, or for tracking them
down when they do occur.
-1-
GNE C/C++ UTILITIES
2 Installation
The easiest way to install the utilities is by running the SETUP
program provided with the utilities which will copy the utilities
to your hard disk and perform any necessary modifications of your
AUTOEXEC.BAT file. As an alternative the utilities may be
installed manually.
Before installation you will need to know the following:
o The drive you are installing from.
o The drive and directory where you wish to install the
utilities. This may be either an existing directory or a
new directory to be created. If you have installed a
previous version of the utilities, then you should use
the same directory, unless you wish to keep the old
version. Note that the SETUP program will not over-write
any of your existing macro files.
o The type of printer you will be using with the utilities.
2.1 System Requirements
To install and run the utilities you will require a PC with the
following:
o Any 8086 compatible processor.
o 256K free RAM.
o Hard disk with 300K free for the installation of the
utilities.
o MS-DOS version 3.0 or later, or a compatible Operating
System.
o A floppy disk drive suitable for the supplied media.
o A printer for use with CPR and CDOC.
The following Printer types are supported:
o PostScript - This is the preferred printer type as it
supports scaleable fonts.
o LaserJet - Any LaserJet II compatible printer.
o Epson compatible dot matrix printer.
o ASCII - This is any printer which doesn't fall into the
above categories. This is the least desirable option as
only the printers default font size will be available and
no highlighting will be possible.
-2-
GNE C/C++ UTILITIES
2.2 Standard Installation
This is the recommended and simplest installation method. The
following steps assume that you are installing from the A: drive.
If you are installing from B: or any other drive/directory, then
use that drive/directory in place of A:
Insert the floppy disk into the drive and enter:
A:\SETUP
You will now need to fill in four input fields. If you wish to
change the supplied default or if you make a mistake, use the
<backspace> key. To move to the next field you can either use the
<return> or <tab> key. Installation may be aborted at this stage
by pressing the <Esc> key. The fields are:
o 'Copy from': This is the drive and directory that you are
installing from. This is validated to make sure that it
does contain the utilities.
o 'Copy to': This is the drive and directory that you will
be installing the utilities in. If this directory doesn't
exist you will be asked for confirmation before it is
created.
o 'Default printer': Enter 'P' for PostScript, 'L' for
LaserJet, 'E' for Epson or 'A' for a plain ASCII printer.
If you use more than one type of printer, specify the one
you use most often.
o 'Modify autoexec.bat': If you answer 'Y' for yes then
your autoexec.bat file will be modified by the setup
program. Your old AUTOEXEC.BAT file will be renamed
before modification to AUTOEXEC.GNE. If you answer 'N'
for no you will be informed at the end of the
installation of any changes that need to be made to your
AUTOEXEC.BAT file before running the utilities.
When you have entered all of these fields you will be asked for
confirmation before continuing. If you answer 'N' for no, you can
edit the four fields again. If you answer 'Y' for yes then the
installation procedure will start copying the files.
When the installation is complete you will be informed if it is
necessary to reboot the computer.
-3-
GNE C/C++ UTILITIES
2.3 Manual Installation
This section is of interest to those who wish to have more
control over the setup process, or want to see the steps taken by
the SETUP program.
For simplification we will assume that the source drive/directory
is A:\ and the destination drive/directory is C:\GNEUTILS. The
following steps should be followed:
o Create the directory C:\GNEUTILS if it doesn't already
exist.
o run the command:
COPY A:\*.EXE C:\GNEUTILS
You may delete C:\GNEUTILS\SETUP.EXE as it is not needed
once the utilities are installed.
o For each of the following files: CB.MAC, CCALLS.MAC,
CDEF.MAC, CPROTO.MAC and FINDDIV.MAC which don't already
exist in C:\GNEUTILS, copy them from A:\ to C:\GNEUTILS.
o For each of the files: CDOC.MAC and CPR.MAC which don't
already exist in C:\GNEUTILS, copy them from one of the
following directories: A:\POSTSCPT, A:\LASERJET, A:\EPSON
or A:\ASCII (depending on your printer) to C:\GNEUTILS.
o In your AUTOEXEC.BAT file ensure that C:\GNEUTILS is
included in your PATH.
o In your AUTOEXEC.BAT file make sure the following line
exists:
SET GNEUTILS=C:\GNEUTILS
This is necessary to pick up the macro files from the
correct place.
o If you modified your AUTOEXEC.BAT file then reboot the
computer.
-4-
GNE C/C++ UTILITIES
3 Common Features
This chapter describes features that are common to one or more of
the utilities.
The following conventions are used in this chapter and the next
when describing the switches:
[ ] Anything within square brackets is optional.
< > Used to represent something that must be specified. Eg.
<num> would represent a number.
| Either what comes before the |, or what comes after it
should be specified, but not both.
3.1 Command Line Arguments
Each utility accepts three different types of arguments; These
are the filenames you want processed, switches which control the
way that the command works and macros which allow groups of
switches to be selected by specifying a single name.
3.1.1 Filenames
Each utility accepts multiple filenames, and the filenames may
include wildcard characters. The wildcard characters which are
supported are '*' and '?'.
3.1.2 Switches
Switches control the way a command works. A switch consists of
either a '/' or a '-' followed by the switch letter which is case
significant, and depending on the particular switch an argument
for the switch may follow without any intervening spaces. The
positioning of switches on the command line is unimportant, ie.
they may appear before or after the filenames, as all of the
switches are processed before the filenames are processed.
3.1.3 Macros
As some of the utilities take a large number of switches which
you may need to use quite frequently, you may define macros to
represent commonly used groups of switches.
Each utility has its own macro file which may be found in the
directory specified by the "GNEUTILS" environment variable, and
will have the same name as the utility but with a ".MAC"
extension.
-5-
GNE C/C++ UTILITIES
The macro file is a plain ASCII file which may be edited with any
text editor. It consists of multiple sections, where each section
defines a single macro. Each section starts with a "+" followed
by an alphanumeric name (no intervening spaces), which is the
name of the macro being defined. This is then followed by the
switches you want this macro to represent. The macro name and
each of the switches must be separated by white space from each
other.
Eg. If the macro file CPR.MAC contained the following:
+std /pp /l80 /c96 /Olpt1
This would define the macro "std" to represent the 4 switches
following it when used with CPR. Comments may be included within
the macro file by preceding them with a '#'. Anything to the
right of the '#' up to the end of the line will be considered to
be a comment.
To use a macro on the command line you simply precede it with a
'+'. Eg. to use the above defined macro for CPR you would use:
cpr +std [files...]
You may mix multiple macros and switches together on the command
line.
In the macro file, the very first macro defined is called the
default macro. If you do not specify any macros on the command
line, you will automatically get the default macro. If you do not
wish to use any macros and you don't require the default macro
then specify '+' followed by white space on the command line.
Eg:
cpr + /pe /l66 /c80
prevents the default macro being used. Note that if you specify
any macros on the command line, then you will not get the default
macro.
All of the utilities are supplied with macros, which may be
tailored to your own requirements. The default macro in each case
has been left empty (apart from the verbose switch, and the
printer selection).
3.2 Printing
Both CPR the source printer and CDOC the source documentor,
produce output which is suitable for being sent direct to a
printer. As there are a large number of switches which are common
to both of these utilities they are described here. These
switches allow specification of the type of printer in use, the
physical paper size, margins, headers and footers. Support is
also provided for double sided printing which can be very
convenient for large listings.
-6-
GNE C/C++ UTILITIES
3.2.1 Page size
This is the logical page size, ie. the number of lines and
columns you wish to use on the page, rather than the physical
page size which is the physical dimensions of the paper. On a
printer with scaleable fonts (or multiple bitmapped fonts) there
need not be a direct relationship between the logical page size
and the physical page size. The following two switches control
the logical page size:
/c<num> Sets the logical page width to be <num> columns.
The maximum number of columns allowed is 256. The
default value is 80.
/l<num> Sets the logical page length to be <num> lines.
The maximum number of lines allowed is 128. The
default value is 66.
Within the logical page area you can specify the printable area,
which may be smaller than the logical page size to allow for
margins. The following four switches control the printable area:
/u<num> Specifies the number of columns available for
printing in. This will be smaller than the number
of columns specified with the /c option if you
wish to have a left or right margin. The default
value is 80.
/m<num> Specifies the left hand margin size in columns.
The default value is 0.
/H<num> Specifies the number of header lines. The
default value is 0.
/F<num> Specifies the number of footer lines. The
default value is 0.
Note that the right hand margin size is the columns in the
logical page minus the sum of the printable columns and the left
hand margin size.
When only one of /u and /c is specified, the other is
automatically calculated using the formulae: /c = /u + /m.
-7-
GNE C/C++ UTILITIES
3.2.2 Headers and Footers
The size and contents of the header and footer is user definable.
Each may consist of up to 9 lines. The headers and footers are
specified with the following switches:
/H<num>[str] Specifies the string for the given header line
which may be in the range 1 (for the top line) to
9. If no string is specified then this header
line is left blank.
/F<num>[str] Specifies the string for the given footer line
which may be in the range 1 (for the top footer
line) to 9. If no string is specified then this
footer line is left blank.
The total number of header lines is the maximum line number
specified in a /H switch. All heading lines up to this line which
have not been specified in a /H switch are left blank. Eg. For 5
heading lines, all of which are blank except the middle one which
has the string "HEADING" you would use the following switches:
/H3STRING /H5
The same applies to the footer lines.
The strings specified in the heading and footer line switches may
consist of up to three sections with each separated with a '~'.
The first section is displayed left justified, the second section
is displayed centre justified and the third section is displayed
right justified.
Each section may contain any ASCII text or keywords. Keywords
are names enclosed within '{' and '}', which will be substituted
by the current value of the keyword when the header/footer is
printed. The following keywords are available:
{File} The name of the file currently being printed.
This is left blank if the standard input is being
used. This is only applicable to CPR.
{FPage} The page number within the file being printed.
This is only applicable to CPR.
{FDate} The last modification date/time of the file being
printed. This is only applicable to CPR.
{Page} The current page number. If printing two or more
pages on a single sheet of paper, then these are
considered to be separate pages.
{Sheet} The current sheet number. This is irrespective of
the number of pages printed on each sheet.
{Date} The current date/time.
-8-
GNE C/C++ UTILITIES
{Kwd} The CDOC keyword for the current comment block.
This is only applicable to CDOC.
{_} Fill the line with the underbar character. This
is suitable for drawing horizontal lines.
If you wish to use the '{' character or the '\' character within
the string, then it must be escaped by preceding it with a '\'
character. If you wish to include spaces in the string then you
must put the string in double quotes.
Eg. To print 3 heading lines with the middle one containing the
string "Middle heading line" centre justified, and two footer
lines, the top one containing a line of underbar characters, and
the bottom one containing the file name left justified, and the
page within the file right justified, the following switches
would be used:
/H3 /H2"~Middle heading line"
/F1{_} /F2{File}~~{FPage}
3.2.3 PostScript printers
The following switch should be used when using a PostScript
printer:
/pp Produce output suitable for a PostScript printer.
The following two switches control the size of the physical page
in 1/72".
/X<num> Width of page.
/Y<num> Height of page.
The default is a width of 594 and a height of 840, which is the
size of an A4 sheet. Note that the width and height refer to the
physical page and are independent of whether printing is being
done in portrait or landscape mode.
As most laser printers can't print to the extreme edge of the
paper a margin is specified around the edges of the page.
Printing will not be attempted in this margin. The margin size
can be set in multiples of 1/72" with the following switch:
/M<num> Page margin size (applies to left, right, top and
bottom).
The default page margin size is set to 25 which should be
suitable for most laser printers. If you find that you are
loosing text at the extreme edges of the paper, then you will
have to increase the margin size with this switch.
When printing, the text will be scaled so that the area occupied
by the lines and columns specified with the /l and /c switches,
will be the page size minus the page margins.
-9-
GNE C/C++ UTILITIES
3.2.4 LaserJet printers
The following switch should be used when using a LaserJet
printer:
/pl Produce output suitable for a LaserJet printer.
The printable area on the physical page my be specified by the
following two switches:
/X<num> Width of the printable area in 1/72" starting
from the origin.
/Y<num> Height of the printable area in 1/72" starting
from the origin.
Note that unlike the PostScript switches which specify the size
of the physical page, these specify the printable area in the
physical page. There is no /M switch. The width and height also
depend on whether the page is being printed in portrait or
landscape mode. Refer to your printer reference manual for more
details.
In portrait mode the default width is 561, and the default height
is 769. In landscape mode the default width is 813 and the
default height is 523. Both of these correspond to an A4 sheet.
Note that unless you have a printer that supports the PCL5
emulation and a scaleable fixed space font, you will have to make
do with the bitmapped font sizes supported by your printer. This
means you will need to adjust the lines and columns on the page
to fill the page as much as possible. In addition you may find
that it is not possible to display text in bold typeface with all
of these fonts.
If you specified a LaserJet compatible printer when installing
the utilities you will find that the macro file for CPR contains
appropriate line and column sizes suitable for the most commonly
supported font sizes.
3.2.5 Epson printers
The following switch should be used when using an Epson
compatible printer:
/pe Produce output suitable for an Epson compatible
printer.
The printable area on the physical page my be specified by the
following two switches:
/X<num> Width of the printable area in 1/72".
/Y<num> Height of the printable area in 1/72".
-10-
GNE C/C++ UTILITIES
Note that unlike the PostScript switches which specify the size
of the physical page, these specify the printable area in the
logical page. There is no /M switch.
The default width is 576, and the default height is 792. This
corresponds to the size of a 11" x 91/2" sheet of tractor fed
paper with a printable width of 8".
Note that Landscape mode is not supported and only four different
font widths (10, 12, 17 and 20 CPI) are supported. Line spacing
may be at either 6 lines per inch or 8 lines per inch.
If you specified an Epson compatible printer when installing
these utilities you will find that the macro file for CPR
contains appropriate line and column sizes suitable for these
font sizes.
3.2.6 ASCII printers
The following switch should be used if your printer does not
support any of the previous emulations:
/pa Produce output in plain ASCII text.
Note that both LaserJet and Epson compatible printers could be
driven with this option, but you would loose control over the
font size and it will not be possible to print in bold.
These is no need to set the physical page size or page margin, so
the /X, /Y and /M switches are all ignored, but you will need to
make sure that the number of lines and columns specified with the
/l and /c switches correspond to a full page for the printer when
used with its default font.
3.2.7 Double sided printing
Double sided printing is available regardless of the printer in
use and allows (with manual intervention) paper to be printed on
both sides. This is achieved by running the utility twice, once
with the /o switch which will print the odd sheets only, and once
with the /e switch which will print the even sheets only, with
the paper being re-inserted into the printer before the utility
is run for the second time.
You will need to determine the correct orientation in which to
re-insert the paper into your printer by either referring to your
printers reference manual, or by experimentation.
-11-
GNE C/C++ UTILITIES
You will also want to ensure that the output is correctly
ordered. Once you know the path that the paper takes through your
printer this should be possible without having to manually re-
order the pages. There are two ways you can control the ordering
from the command line:
o Print the even pages before the odd pages, as this
changes the final ordering of the pages.
o Use the /r switch which will print the pages in reverse
order.
3.3 Limitations
The following limitations apply to source files:
o The maximum line length supported is 256 characters.
o Apart from CDEF, the utilities do not perform any pre-
processing. This implies that if you have re-defined any
of the C/C++ keywords or any of the C/C++ operators then
the results are likely to be unpredictable.
-12-
GNE C/C++ UTILITIES
4 Command Reference
Syntax for all of the commands is similar. It takes the form:
command [switches and macros] [files...]
Where command is one of 'cb', 'ccalls', 'cdef', 'cdoc',
'cproto', 'cpr' and 'finddiv'.
If files are specified the source is read from these, otherwise
the standard input is read. The output is always sent to the
standard output, except for cdoc and cpr where it may optionally
be sent to a file or a device.
The following two switches are available for use with all of the
utilities:
/? Gives online help regarding the use of the
utility.
/v Sets verbose mode. When this mode is set the
utilities report their progress as they process
each file in the file list.
None of the utilities directly modify the original file. If you
wish to change the original file, say TEST.C with say CB, you
would need to run the following commands:
RENAME TEST.C TEST.OLD
CB TEST.OLD > TEST.C
Before deleting TEST.OLD you should make sure that TEST.C is
correct.
-13-
GNE C/C++ UTILITIES
4.1 CB - Source Reformatter
CB allows the indentation style and other layout characteristics
of source code to be changed. The required characteristics of the
indentation and layout is specified by switches.
CB is suitable for converting code written by other people into
the style of layout you use, thereby making it easier to read. It
can also be used to ensure that the layout of code written within
a team or company all follows the same layout standards.
Note that the layout of array and structure initialisation is not
changed, as the original authors layout for these is usually the
best.
4.1.1 Basic Switches
/ik[num] Reformat the source to use Kernighan & Ritchie
style indenting. If [num] is specified then this
will be used as the number of spaces to indent
each level by. If it is not specified, then a
tab character will be used for each indentation
level. The following is an example of Kernighan &
Ritchie layout:
if (test) {
/* */
}
/ia[num] Reformat the source to use Allman style
indenting. If [num] is specified then this will
be used as the number of spaces to indent each
level by. If it is not specified, then a tab
character will be used for each indentation
level. The following is an example of Allman
layout :
if (test)
{
/* */
}
/iw[num] Reformat the source to use Whitesmiths style
indenting. If [num] is specified then this will
be used as the number of spaces to indent each
level by. If it is not specified, then a tab
character will be used for each indentation
level. The following is an example of Whitesmiths
layout:
if (test)
{
/* */
}
-14-
GNE C/C++ UTILITIES
/f Format the function definitions using the spacing
specified with the /s switches. The default is to
leave them unaltered.
/c If there are multiple trailing spaces in a
comment then replace them with a single space.
This is useful for source where all the comments
end in the same column, but after changing the
indentation the ends of the comments are no
longer aligned.
/c<num> This will add trailing spaces to a comment to
make the */ finish in the specified column, where
possible.
/t<num> This specifies the tab size for the output
source. It is used together with the /T option,
to ensure that the indentation of the second and
subsequent lines of multi-line statements
relative to the first line of the statement is
maintained. The default value is 8
/T<num> This specifies the tab size for the input source.
It is used together with the /t option as
discussed above. The default value is 8.
/S When displaying case statements, the case is
indented within the switch. The default is to
display the case and the switch with the same
indentation.
/w When displaying 'do { ... } while ( ... );'
statements, put the 'while' on the same line as
the '}'. This helps the readability of the code,
as it prevents the while part of the statement
from looking like a while statement with an empty
body. Note that this is always the case when
using Kernighan & Ritchie layout, but with Allman
and Whitesmiths layout the '}' and the 'while'
will be put on different lines by default.
4.1.2 Spacing Switches
The following switches all control the spacing between particular
tokens. Each switch takes a numeric parameter which may be either
0 or 1. If 0 is used then there will be no space between the
specified tokens. If 1 is used then there will be a single space
between the specified tokens. If the switch is not used then the
original spacing is maintained.
/su<0|1> Specifies the spacing between a unary operator
and its operand.
/sb<0|1> Specifies the spacing between a binary operator
and both of its operands.
-15-
GNE C/C++ UTILITIES
/sp<0|1> Specifies the spacing on the inside of opening
and closing parenthesis.
/sr<0|1> Specifies the spacing between both structure
member operators ('.') and structure member
pointers ('->'), and their structures and
members. When processing C++ source the spacing
around '::', '.*' and '->*' is also modified.
/sR<0|1> Specifies the spacing between 'return' and the
opening parenthesis.
/sf<0|1> Specifies the spacing between a function name
used in a function call and the opening
parenthesis.
/st<0|1> Specifies the spacing between 'for', 'if' or a
'while' and the opening parenthesis.
/sc<0|1> Specifies the spacing in front of a ','.
/sC<0|1> Specifies the spacing after a ','.
/se<0|1> Specifies the spacing between the last token in a
statement and the statement terminator (';').
/ss<0|1> Specifies the spacing in front of the semi-colons
in a 'for' statement.
/sS<0|1> Specifies the spacing after the semi-colons in a
'for' statement.
4.1.3 Examples
To produce a layout similar to that used by K&R in "The C
programming language" you would use the following:
/ik5 The 'k' specifies the "K&R" indentation layout
and the 5 specifies the number of spaces to
indent each level by.
/c Remove multiple trailing spaces in comments and
replace with a single space.
/su0 No space between unary operators and their
operands.
/sb1 Single space between binary operators and both of
their operands.
/sp0 No space on the inside of parenthesis.
/sr0 No space either side of a '.' or a '->'.
/sR0 No space between 'return' and '('.
-16-
GNE C/C++ UTILITIES
/sf0 No space between the function name and the '(' in
a function call.
/st1 Single space between 'for', 'if' or 'while' and
'('.
/sc0 No space in front of a ','.
/sC1 Single space after a ','.
/se0 No space in front of the ';' at the end of a
statement.
/ss0 No space in front of a ';' used in a for
statement.
/sS1 Single space used after a ';' in a for statement.
/f Apply the above /s switches to the function
definition as well.
When you have decided on the switches appropriate to your layout
style, you are advised to set up a macro for them, so you don't
have to type in all of the switches every time you use the
utility. If you set up the default macro (the first macro in the
macro file) then you will not need to specify any switches or
macros on the command line (remember that the default macro is
always used, unless you specify a '+' or another macro on the
command line). So if you have a source file OLD.C and you wanted
to produce a file NEW.C which conforms to your layout style, you
would use:
CB OLD.C > NEW.C
You should not delete the old file until you have checked that
the new file is correct.
-17-
GNE C/C++ UTILITIES
4.2 CCALLS - Call Tree Display
CCALLS can be used to show any of the following:
o The caller/called tree. This is shown by default unless
any of the /r, /s or /u switches are used. The
caller/called tree will show for a single function which
functions it call. Then for each of these functions, the
functions that they call are displayed, and so on. This
is suitable for viewing the overall structure of a
program.
o The called/caller tree. This is selected with the /r
switch. The called/caller tree will show for a single
function which functions call it. Then for each of these
functions, the functions that call them are displayed,
and so on. This is suitable for finding all possible call
paths to a single function.
o The functions that could be made static. This is selected
with the /s switch.
o The functions that are not called. This is selected with
the /u switch.
For each function listed in the call tree, the file name and line
number where it is defined is also printed.
As CCALLS does not do any pre-processing, it can't tell the
difference between a function call and a macro, so both are
included in the call tree. CCALLS is not suitable for use with
C++ source as it will not show member functions.
4.2.1 Basic Switches
/r Reverse the order of the tree, so that for a
particular function , all of the functions that
call it are shown. By default all of the
functions that it calls are shown.
/e Include in the tree those functions which are
called but not defined within the source files.
When these functions are included in the tree
they are marked as "external". By default
external functions are not shown.
/f[func] Start the tree with the specified function. By
default the starting function is "main". If the
/f switch is used without a function name then
CCALLS will attempt to show the call tree for all
functions that are not called themselves.
/i After the tree print an alphabetically sorted
index of which line each function first appears
on.
-18-
GNE C/C++ UTILITIES
/l<num> Specifies the maximum depth of the tree to
display. A value of 0 would display just the
starting function, a value of 1 would display the
starting function and all those functions that it
calls (or is called by if /r is set), and so on.
By default there is no limit to the depth of the
tree.
/t<num> Specifies the indentation to use for each level
of the tree. The default is to use 4 characters
for each indentation level.
/n Precede each line with its line number. This is
useful as many of the lines will reference other
lines to avoid duplication within the tree.
4.2.2 Special Switches
The following two switches can't be used together or with the
above switches. They do not display a tree, but show a list of
functions that match a certain criteria.
/s This displays a list of all those functions that
are not called from functions in other files and
are not already defined as 'static'. It's purpose
is to locate those functions that could be made
static. Before making any of these functions
static you should make sure that they are not
called indirectly, ie. via a pointer to a
function or from a file that was not specified in
the command line arguments.
/u This displays a list of all those functions that
are not called from any of the other functions in
the files specified in the command line
arguments. Before deleting any of these functions
you should make sure that they are not called
indirectly, ie. via a pointer to a function or
from a file that was not specified in the command
line arguments.
4.2.3 Advanced Switches
The following switches control the size of internal tables. These
have a default size which should be sufficient for most programs.
The size of the tables may be increased at the cost of needing
more memory.
/C<num> This specifies the maximum number of different
functions (including external functions) that are
called. The default value is 1024.
-19-
GNE C/C++ UTILITIES
/F<num> This specifies the maximum number of function
definitions. The default value is 1024.
/S<num> This specifies the maximum number of strings to
store in the string table. An entry is added to
the string table for each filename being
processed, for each function definition and for
each function called. The default value is 1024.
4.2.4 Examples
If the file TEST.C contains the following source code:
main(int argc, char *argv[])
{
int i;
if (argc < 2) {
ShowUsage();
exit(1);
}
for (i = 1; i <= argc; i++) {
PrintArg(i, argv[i]);
}
}
static void ShowUsage(void)
{
printf("Usage: test [args...]\n");
}
void PrintArg(int ArgNum, char *pArg)
{
printf("Arg %d = %s\n", ArgNum, pArg);
}
void TestArg(void)
{
PrintArg(1, "Test Arg");
}
To show the caller/called tree, use:
CCALLS TEST.C
This will produce the following output:
main [TEST.C,1]
| ShowUsage [TEST.C,15]
| PrintArg [TEST.C,20]
If you wanted to show the caller/called tree with externals you
would use:
CCALLS /e TEST.C
-20-
GNE C/C++ UTILITIES
This will produce the following output:
main [TEST.C,1]
| ShowUsage [TEST.C,15]
| | printf [External]
| exit [External]
| PrintArg [TEST.C,20]
| | printf [External]
To show all possible ways that printf() could be called, use:
CCALLS /r /fprintf TEST.C
This will produce the following output:
printf [External]
| ShowUsage [TEST.C,15]
| | main [TEST.C,1]
| PrintArg [TEST.C,20]
| | main [TEST.C,1]
| | TestArg [TEST.C,25]
To show all functions that could be made static use:
CCALLS /s TEST.C
This would produce the following output:
main [TEST.C,1]
PrintArg [TEST.C,20]
TestArg [TEST.C,25]
Note that main() function is included in this list because it is
not called from any of the functions that CCALLS processed, but
is called by the C start up code, so it can't be made static.
To show all functions that are not called, use:
CCALLS /u TEST.C
This will produce the following output:
main [TEST.C,1]
TestArg [TEST.C,25]
Note that main() function is included in this list because it is
not called from any of the functions that CCALLS processed, but
is called by the C start up code, so it can't be deleted.
-21-
GNE C/C++ UTILITIES
4.3 CDEF - #ifdef Remover
If source code supports conditional compilation (code within #if,
#ifdef and #ifndef statements), it can at times be difficult to
read easily, especially if there are a large number of
conditional statements or they are nested. CDEF allows you to
remove conditional compilation on a per identifier basis. Eg. if
code uses both 'TEST' and 'DEBUG' for conditional compilation
then it is possible to remove the conditional compilation for
either 'TEST' or 'DEBUG' singly, or for both.
4.3.1 Switches
/D<symbol>[=value] Treat the symbol as being defined. If the
value is specified then it is set to that value.
/U<symbol> Treat the symbol as being undefined.
4.3.2 Examples
If you have a lot of "#ifdef DEBUG" statements in your code which
are no longer needed and are now hindering readability use the
following switch:
/UDEBUG
This would convert code fragments which looked like:
#ifdef DEBUG
printf("Debugging version\n");
#else
printf("Production version\n");
#endif
to:
printf("Production version\n");
Alternatively if you used the switch:
/DDEBUG
The above code fragment would be converted to:
printf("Debugging version\n");
Remember that the output of CDEF could be piped directly into CPR
to print the file after removing the conditional compilation,
without the need to change the original or to create temporary
versions of the file.
-22-
GNE C/C++ UTILITIES
4.4 CDOC - Code Documentor
CDOC provides an easy method to document functions/data
structures etc. within a library or program, by extracting
specially marked comment blocks which can then be sorted into
alphabetical order before printing.
A comment block may be a single comment, or multiple contiguous
comments (only separated by white space) if the /j switch is
used. The comment block must also have a single alphabetic
character immediately after the start of the comment, ie. no
spaces are allowed between the '//' or '/*' and the alphabetic
character. The case of this character is not significant. This
character is used as an identifier for different types of comment
blocks. For example you may use the letter 'F' to identify all
comment blocks that document functions, and the letter 'D' to
identify all comment blocks that document data structures. Using
the /d switch you can then choose which comment blocks you are
interested in.
A comment block may optionally have a keyword associated with it.
If used this keyword can be used for sorting the comment blocks
into alphabetical order on the keyword, for use in the headers
and footers and also for producing indexes. The keyword may
appear any where inside the comment block, but must be preceded
by a '%'. When the comment block is printed the '%' is replaced
with a space and the keyword appears in bold if your printer
supports bold highlighting.
It is possible to make other words in a comment block appear in
bold be inserting '$b' in front of them.
4.4.1 Basic Switches
/p<a|e|l|p> Sets the printer type. Set to one of the
following:
/pa - ASCII output
/pe - output suitable for an Epson printer.
/pl - output suitable for a LaserJet printer.
/pp - output suitable for a PostScript printer.
/l<num> Sets <num> lines to use on the sheet of paper.
This is the total number of lines including
header and footer lines.
/c<num> Sets <num> columns across the sheet of paper to
use. This is the total number of columns
including left and right hand margins.
/m[o|e]<num> Sets the left hand margin to be <num> columns. If
/mo is used then the margin is set for odd
numbered pages only. If /me is used then the
margin is set for even numbered pages only.
-23-
GNE C/C++ UTILITIES
/u<num> Sets the number of columns that data may be
printed in. This value plus the left hand margin
size must be less than or equal to the total
columns across the sheet set by /c. If it is less
than the total columns then any remaining columns
are in effect a right hand margin.
/H[o|e]<num>[str] Sets the specified header line for the
page. If /Ho is used then the header line is only
set for the odd numbered pages, and likewise /He
sets the header line for the even numbered pages
only. See section 3.2.2 for more details.
/F[o|e]<num>[str] Sets the specified footer line for the
page. If /Fo is used then the footer line is only
set for the odd numbered pages, and likewise /Fe
sets the footer line for the even numbered pages
only. See section 3.2.2 for more details.
/O<file> Specifies that the output should be sent to
<file> rather than to the standard output. This
is useful when used in a macro to send the output
direct to a printer, removing the need to
redirect the output on the command line.
/t<num> Sets the tab positions to be every <num> columns.
Default is 8.
/d<char> Document those comments that use the specified
character identifier. Multiple character
identifiers may be used if necessary. The default
is for no identifiers to be selected, so if you
find that nothing is being printed, make sure
that you have used the /d switch with the correct
identifies.
/j Treat multiple contiguous comments as being a
single comment. This is useful if a comment block
is made up of multiple single line comments.
/s Before printing the document sort the comment
blocks into alphabetical order using the keyword.
/x Do not include the start of the comment, ie. '/*'
or '//' and the following character identifier,
or the end of the comment.
/x<char> In addition to deleting the start and end of the
comment as in /x, delete all leading and trailing
occurrences of the specified character. This is
useful when a box has been drawn around the
comment.
-24-
GNE C/C++ UTILITIES
4.4.2 Feature Switches
/bH Prints the page header in bold.
/bF Prints the page footer in bold.
/n Starts each comment block on a new page.
/nf Starts each comment block on a new page if it
will not fit on the current page. This is the
default.
/np Starts each comment block on a new page if the
next paragraph will not fit on the current page.
/n<1-9> Starts each comment block on a new page if the
specified number of lines will not fit on the
current page.
/i At the end of the source listing, print out an
index of the keywords against the page number
that the keyword was printed on.
/q Queries the number of pages required to print the
document, but does not print anything.
4.4.3 Advanced Switches
/o Prints the odd numbered pages only.
/e Prints the even numbered pages only.
/r Prints the pages in reverse order.
/X<num> Sets the width of a page in 1/72". See sections
3.2.3 - 3.2.6 for more details.
/Y<num> Sets the height of a page in 1/72". See sections
3.2.3 - 3.2.6 for more details.
/M<num> Sets the un-printable margin around a page in
1/72". See sections 3.2.3 - 3.2.6 for more
details.
-25-
GNE C/C++ UTILITIES
4.4.4 Examples
If each entry point to a library has a comment block of the form:
/*E
*** Function: %FunctionName()
***
*** Description: Function description
***
*** Parameters: int $bParam1 Param description
***
*** Return Value: void
**/
and you wish to produce a document containing all of the entry
points, sorted into alphabetical order, but without any of the
"*" characters or the start and end of the comment lines, you
would use the following switches:
/dE /s /x*
The above comment block when printed would appear as:
Function: FunctionName()
Description: Function description
Parameters: int Param1 Param description
Return Value: void
-26-
GNE C/C++ UTILITIES
4.5 CPR - Source Printer
CPR prints source code with support for double sided printing and
multiple pages on each side of the paper. To assist finding
function definitions, options exist to display function names in
bold and to print an index giving the file name and page number
for all function definitions.
4.5.1 Basic Switches
/p<a|e|l|p> Sets the printer type. Set to one of the
following:
/pa - ASCII output
/pe - output suitable for an Epson printer.
/pl - output suitable for a LaserJet printer.
/pp - output suitable for a PostScript printer.
/l<num> Sets <num> lines to use on the sheet of paper.
This is the total number of lines including
header and footer lines.
/c<num> Sets <num> columns across the sheet of paper to
use. This is the total number of columns
including left and right hand margins.
/m[o|e]<num> Sets the left hand margin to be <num> columns. If
/mo is used then the margin is set for odd
numbered pages only. If /me is used then the
margin is set for even numbered pages only.
/u<num> Sets the number of columns that data may be
printed in. This value plus the left hand margin
size must be less than or equal to the total
columns across the sheet set by /c. If it is less
than the total columns then any remaining columns
are in effect a right hand margin.
/H[o|e]<num>[str] Sets the specified header line for the
page. If /Ho is used then the header line is only
set for the odd numbered pages, and likewise /He
sets the header line for the even numbered pages
only. See section 3.2.2 for more details.
/F[o|e]<num>[str] Sets the specified footer line for the
page. If /Fo is used then the footer line is only
set for the odd numbered pages, and likewise /Fe
sets the footer line for the even numbered pages
only. See section 3.2.2 for more details.
/O<file> Specifies that the output should be sent to
<file> rather than to the standard output. This
is useful when used in a macro to send the output
direct to a printer, removing the need to
redirect the output on the command line.
-27-
GNE C/C++ UTILITIES
/n Prints the line number at the start of each line
of source.
/t<num> Sets the tab positions to be every <num> columns.
Default is 8.
4.5.2 Feature Switches
/bc Prints comments in bold.
/bk Prints all keywords in bold.
/bK Prints the keywords which affect the control of
flow in bold. Ie. the following keywords are
displayed in bold: 'goto', 'return', 'break',
'continue', 'if', 'else', 'for', 'do', 'while',
'switch', 'case' and 'default'.
/bf Prints the function names within function
definitions in bold.
/bH Prints the page header in bold.
/bF Prints the page footer in bold.
/f<function> Prints the specified function only. If there is a
comment immediately preceding the function then
this is considered to be part of the function and
is printed as well. Multiple /f switches may be
specified to print out more than one function at
a time.
/i At the end of the source listing, print out an
index of the functions containing the file and
page number where the function was defined.
/j If a line is too long to fit in the available
columns then continue it on the next line left
justified. The default is to continue it on the
next line right justified.
/s Start each function on a new page. If there is a
comment immediately preceding the function then
this is printed on the new page as well.
/x Ignore any form feed characters in the source.
The default is to start a new page when a form
feed character is encountered.
/<1-9> Specifies the number of pages to print on each
sheet of paper. The pages are separated from
each other by two spaces. The default is to print
one page on each sheet of paper.
-28-
GNE C/C++ UTILITIES
/a When printing multiple pages on each sheet of
paper, allow multiple files to be printed on the
same sheet (but in different pages). Default is
to start a new sheet regardless of how many pages
are unfilled on the current sheet.
/L Print in landscape mode (if supported by the
printer). Default is to print in portrait mode.
/q Queries the number of pages required to print the
source files, but does not print anything.
4.5.3 Advanced Switches
/o Prints the odd numbered sheets only.
/e Prints the even numbered sheets only.
/r Prints the sheets in reverse order.
/X<num> Sets the width of a page in 1/72". See sections
3.2.3 - 3.2.6 for more details.
/Y<num> Sets the height of a page in 1/72". See sections
3.2.3 - 3.2.6 for more details.
/M<num> Sets the unprintable margin around a page in
1/72". See sections 3.2.3 - 3.2.6 for more
details.
4.5.4 Examples
To print a file TEST.C to a PostScript printer using 80 columns
and 66 lines with a two line heading containing the file name,
date and page number use:
CPR /pp /c80 /l66 /H1{File}~{FDate}~{FPage} /H2 TEST.C
To print the same file with two pages on each sheet of paper, the
following switches would need to be added to the above command:
/2 Specifies to print 2 pages on each sheet.
/L Print in landscape as this will give the text a
better aspect ratio than printing in portrait
orientation.
/c162 Each page will need 80 columns and there is
always 2 empty columns between the pages.
For further examples, see the CPR.MAC macro file which will
contain examples appropriate to your printer.
-29-
GNE C/C++ UTILITIES
4.6 CPROTO - Function Prototype Generator
CPROTO provides a quick way of producing function prototypes
(which retain the original data types). Ability to process only
static or global functions is also provided, as the prototypes
for each are usually needed in different places.
/d Don't display the parameter names in the
prototype. The default is to display them.
/g Display the prototypes for global (non-static)
functions only. The default is to display
prototypes for all functions. See /s as well.
/s Display the prototypes for static functions only.
The default is to display prototypes for all
functions. See /g as well.
/m Display the prototypes for C++ member functions.
The default is not to display these. These would
need to be edited before being included in the
class.
4.6.1 Examples
To generate the prototypes of the static functions only, which
you would probably want to include at the top of the source file,
use the following switch:
/s
To generate the prototypes of the functions which are not static,
which you would probably want to include in a header file, use
the following switch:
/g
-30-
GNE C/C++ UTILITIES
4.7 FINDDIV - Divide by Zero Finder
Searches source files for all possible / and % operations. This
makes it suitable for finding places where divide by zero errors
could occur.
Each line that contains a / or % operation is printed out
preceded by the file name and the line number where the operation
is located.
4.7.1 Examples
To find all locations where / and % operations occur in the C
source files within the current directory, use:
finddiv *.c
Finddiv would then print out each line that contained one of the
two operators, along with its location. It is then a matter of
checking each of these lines to see if it could perform a divide
by zero.
-31-
GNE C/C++ UTILITIES
Appendix A - Error messages
All error messages are preceded with a 6 character code. The
first two characters are alphabetic and identify the application,
and the last four which are all digits is the error code.
The first two characters will be one of the following:
Code Application
CB CB
CC CCALLS
CD CDOC
CF CDEF
CO CPROTO
CP CPR
FD FINDDIV
In the following list of error messages, a %s represents a string
and %d represents a number which relate to the item in error.
Each error message in the following list is preceded by its four
digit error code.
0100 Can't open file: %s
The given filename which was specified as one of the arguments to
the utility can't be opened.
0101 Switch %s invalid
The specified switch is invalid for this utility. Use /? to get a
list of all valid switches for this utility.
0102 Can't open output file: %s
The filename which was specified with a /O switch can't be
created. Either the filename is invalid or the file already
exists and is write protected.
0103 '%s' is an invalid option for the '%s' switch
The given switch was not expecting the option it was given. Use
/? to get a list of all valid switches and options for those
switches.
0105 Tab size must be between 1 and 64
The tab size must be in the given range.
0106 Number of printer columns must be between %d and %d
The number of columns specified with the /c switch must be in the
given range.
-32-
GNE C/C++ UTILITIES
0107 Number of usable columns must be between %d and %d
The number of columns specified with the /u switch must be in the
given range.
0108 Number of lines must be between %d and %d
The number of lines specified with the /l switch must be in the
given range.
0109 Left margin size must be between %d and %d
The left margin size specified with the /m switch must be in the
given range.
0110 Left margin size for odd pages must be between %d and %d
The left margin size specified with the /mo switch must be in the
given range.
0111 Left margin size for even pages must be between %d and %d
The left margin size specified with the /me switch must be in the
given range.
0112 Sum of header and footer lines must be < number of lines
The total number of header and footer lines specified with the /H
and /F switches must be less than the total number of lines per
page specified with the /l switch.
0113 Page margin must be between %d and %d
The page margin size specified with the /M switch must be in the
given range.
0114 Can't open macro file %s
The specified macro file could not be opened. The utilities
expect to find their macro files within the directory specified
in the GNEUTILS environment variable. Check that this is
correctly set up in your AUTOEXEC.BAT file.
0115 Can't find macro %s
The macro you specified as a parameter (proceeded with a '+')
can't be found in the macro file for the utility. Check that you
have spelt the macro name correctly. Note that the case of the
macro is not significant.
0116 Page width too small
The page width specified with the /X switch is too small.
-33-
GNE C/C++ UTILITIES
0117 Page height too small
The page height specified with the /Y switch is too small.
0118 Comment end column must be between %d and %d
The comment end column specified with the /c switch must be in
the given range.
0119 Indentation size must be between %d and %d
The indentation size specified with the /i switch must be in the
given range.
0120 %s is an invalid indentation style
The indentation style specified with the /i switch is invalid.
Use the /? switch to see valid indentation styles.
0121 Source tab size must be between %d and %d.
The tab size specified with the /T switch must be in the given
range.
0200 Insufficient memory
There is insufficient memory to run the utility. This should not
happen on a 'normal' system. Check to see what else is already
loaded into memory.
0201 Insufficient memory to read ahead %d tokens
If the number of tokens specified is large (greater than 100),
then check too see if you are trying to process a non C/C++
source file. When using CPR avoid using the /bf, /p and /f
switches with non C/C++ source files. If the number of tokens
specified is small, then check to see what else is already loaded
into memory.
0202 Insufficient string space
The number of strings exceeded the size of the string table. Use
the /S switch to increase the size of the string table.
0300 Aborted by user
The program was aborted by pressing either <Ctrl>+C or
<Ctrl>+<Break>.
0400 Write failed
A write operation failed. Check there is sufficient disk space,
or that the printer is on-line etc.
-34-
GNE C/C++ UTILITIES
0500 Can't create temporary file %s
An attempt to create the specified directory name failed.
Temporary files are created in the directory specified by the TMP
environment variable. If the TMP environment variable is not set
then TEMP is used. If this is not set, then they are created in
the current directory.
0600 Switch '%s' encountered
The specified switch is unavailable for use in your version of
the utility.
0700 Too many blocks
CDOC can only process a maximum of 512 comment blocks.
0701 Too many defines
CDEF can only process a maximum of 40 defines/un-defines at a
time. If you need more then use multiple passes using up to 40
defines each time.
0702 Too many functions
The number of functions in the source exceeded the size of the
function table. Use the /F switch to increase the size of the
table.
0703 Too many calls
The number of function calls in the source exceeded the size of
the function call table. Use the /C switch to increase the size
of the table.
0800 Too many levels of #if/#ifdef/#ifndef in %s at line %d
CDEF will only allow up to 40 nested levels of pre-processor
statements.
0801 #elif without matching #if in %s at line %d
Check that the source you are processing is correct.
0802 #else without matching #if in %s at line %d
Check that the source you are processing is correct.
0803 #endif without matching #if in %s at line %d
Check that the source you are processing is correct.
0804 Output line too long in %s at line %d
The source line after pre-processing by CDEF is longer than 256
characters.
-35-
GNE C/C++ UTILITIES
0805 Non pre-processor token in %s at line %d
Check that the specified line of source is correct.
0806 Unexpected operand in %s at line %d
Check that the specified line of source is correct.
0807 Expression too complex in %s at line %d
Try to simplify the expression on the specified line.
0808 Unexpected operator in %s at line %d
Check that the specified line of source is correct.
0809 Unexpected ( in %s at line %d
Check that the specified line of source is correct.
0810 Matching ( not found in %s at line %d
A ')' was found for which there wasn't a matching '('.
0811 Unexpected ) in %s at line %d
Check that the specified line of source is correct.
0812 Unmatched ( in %s at line %d
A '(' was found for which there wasn't a matching ')'.
0813 Invalid argument for defined operator in %s at line %d
The defined() operator was given an invalid parameter.
0814 Divide by zero in %s at line %d
The expression involves performing a divide by zero.
-36-